From 1a9e4a4d180a970f73e90a82e4b72ad79fa50457 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Wed, 22 Feb 2006 19:28:25 +0000 Subject: [PATCH] Optimize arc filter to stop computing distances once a point is close enough git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1748 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/arcdist.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/gpsbabel/arcdist.c b/gpsbabel/arcdist.c index 27499bf1e..be5d1576b 100644 --- a/gpsbabel/arcdist.c +++ b/gpsbabel/arcdist.c @@ -90,20 +90,6 @@ arcdist_process(void) QUEUE_FOR_EACH(&waypt_head, elem, tmp) { waypointp = (waypoint *)elem; - if ( ptsopt ) { - dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0, - waypointp->latitude*M_PI/180.0, - waypointp->longitude*M_PI/180.0 ); - } - else { - dist = linedist(lat1, lon1, lat2, lon2, - waypointp->latitude, - waypointp->longitude ); - } - - /* convert radians to float point statute miles */ - dist = tomiles(dist); - if ( waypointp->extra_data ) { ed = (extra_data *) waypointp->extra_data; } @@ -111,10 +97,26 @@ arcdist_process(void) ed = (extra_data *) xcalloc(1, sizeof(*ed)); ed->distance = BADVAL; } - if ( ed->distance > dist ) { + if ( ed->distance == BADVAL || ed->distance >= pos_dist ) { + if ( ptsopt ) { + dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0, + waypointp->latitude*M_PI/180.0, + waypointp->longitude*M_PI/180.0 ); + } + else { + dist = linedist(lat1, lon1, lat2, lon2, + waypointp->latitude, + waypointp->longitude ); + } + + /* convert radians to float point statute miles */ + dist = tomiles(dist); + + if ( ed->distance > dist ) { ed->distance = dist; + } + waypointp->extra_data = ed; } - waypointp->extra_data = ed; } } lat1 = lat2; -- 2.30.2